package com.symaster.common.connect.test;

import com.symaster.common.connect.tcp.TcpElementR;
import com.symaster.common.util.IOUtil;

import javax.swing.*;

/**
 * @author yinmiao
 * @version 2022-05-03 17:25
 */
public class TcpTestR {
    public static void main(String[] args) {
        new Thread(() -> {
            TcpElementR tcpElementR = null;
            try {
                tcpElementR = new TcpElementR(TestCommon.masterPort);
                tcpElementR.setConnectSuccessListener(() -> System.out.println("已连接"));
                tcpElementR.setConnectClosedListener(() -> System.out.println("连接断开"));
                tcpElementR.setMessageHandler(message -> JOptionPane.showInputDialog(null, message, "接收到信息", JOptionPane.PLAIN_MESSAGE));
            } catch (Exception e) {
                IOUtil.close(tcpElementR);
            }
        }).start();
    }
}
